package com.bss.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import com.andy.basics.AbstractEntity;

@Entity
@Table(name = "person")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Person extends AbstractEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1839287856672445577L;

	private int id;

	/**
	 * This field will be null if id type is not passport
	 */
	private Passport passport = new Passport();

	private String sex;

	private Date dateOfBirth;

	private IdCardType idcardtype = new IdCardType();

	private Profession profession = new Profession();

	private byte[] photo;

	/**
	 * This field will be null if id type is passport
	 */
	private String idCardNumber;

	@Id
	@Column(name = "id", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return this.id;
	}

	@Override
	public void setId(final int id) {
		this.id = id;
	}

	@NotNull(message = "{person.idCardType.NotNull}")
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idIdCardType")
	public IdCardType getIdCardType() {
		return this.idcardtype;
	}

	public void setIdCardType(final IdCardType idcardtype) {
		this.idcardtype = idcardtype;
	}

	@NotNull(message = "{person.profession.NotNull}")
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idProfession")
	public Profession getProfession() {
		return this.profession;
	}

	public void setProfession(final Profession profession) {
		this.profession = profession;
	}

	@NotNull(message = "{person.sex.NotNull}")
	@Pattern(regexp = "M|F", message = "{person.sex.Pattern}")
	public String getSex() {
		return this.sex;
	}

	public void setSex(final String sex) {
		this.sex = sex;
	}

	@Size(max = 20, message = "{person.idCardNumber.Size}")
	public String getIdCardNumber() {
		return this.idCardNumber;
	}

	public void setIdCardNumber(final String idCardNumber) {
		this.idCardNumber = idCardNumber;
	}

	public byte[] getPhoto() {
		return this.photo;
	}

	public void setPhoto(final byte[] photo) {
		this.photo = photo;
	}

	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	@NotNull(message = "{person.dateOfBirth.NotNull}")
	@Temporal(TemporalType.DATE)
	@Column(name = "dateOfBirth")
	public Date getDateOfBirth() {
		return this.dateOfBirth;
	}

	public void setPassport(Passport passport) {
		this.passport = passport;
	}

	@OneToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idPassport")
	public Passport getPassport() {
		return this.passport;
	}

	@Override
	public String toString() {
		return "N/A";
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date", length = 19)
	public Date getDate() {
		return this.date;
	}

}
